<?php

namespace App\Services\UserInviteInfo;

use App\Models\User;
use App\Models\Product;

class MakeUserInviteRoute
{
	/**
	 * @var null | User
	 */
	protected $user = null;

	/**
	 * @var null | Product
	 */
	protected $product = null;

	protected $channel = 'wap'; // wap, app, mini

	protected $inviteString;


	public function __construct(
		User $user,
		Product $product = null,
		$channel = 'wap')
	{
		$this->user = $user;
		$this->product = $product;
		$this->channel = $channel;

		$this->inviteString = app(UserInviteInfo::class, [
			'user' => $user,
			'product' => $product,
			'channel' => $channel
		])->inviteString();
	}

	protected function inviteRoute()
	{
		$prefix = app()->environment('production') ? 'wap' : 'dwap';

		$query = $this->inviteString;

		if ($this->product) {
			$route = "https://{$prefix}.pandago.shop/#/packs/pages/product/show?query={$query}";
		} else {
			$route = "https://{$prefix}.pandago.shop/#/packs/pages/auth/auth?query={$query}";
		}

		return $route;
	}

	public function make()
	{
		if ($this->channel === 'wap') {
			return $this->inviteRoute();
		}

		return null;
	}
}
